React JS:
用來實作使用者介面的 JavaScript 函式庫
import React, { Component } from 'react';
/*import OpenLayer from './OpenLayer.js'*/
import ToDoList from './ToDoList.js'
export class Map extends Component {
render() {
/*return <OpenLayer />*/
return <ToDoList />
}
}
import { React, useState } from "react";
import Form from 'react-bootstrap/Form';
import InputGroup from 'react-bootstrap/InputGroup';
import Button from 'react-bootstrap/Button';
function GetData() {
return [{
Key: 1,
Name: '上班',
Checked: true
}, {
Key: 2,
Name: '吃飯',
Checked: false
}, {
Key: 3,
Name: '睡覺',
Checked: false
}, {
Key: 4,
Name: '摸魚',
Checked: true
}]
}
function ToDoList() {
const [datas, setDatas] = useState(GetData());
return (
<>
{
datas.map((data) => (
<ToDoListItem
key={data.Key}
Name={data.Name}
Checked={data.Checked}
onDelete={() => {
setDatas(datas.filter((a)=> a.Key !== data.Key))
}}
></ToDoListItem>
))
}
</>
);
}
export default ToDoList;
function ToDoListItem(props) {
return (
<InputGroup>
<InputGroup.Checkbox key={props.Key} checked={props.Checked} />
<Form.Control value={props.Name} />
<Button variant="danger" onClick={props.onDelete} >刪除</Button>{' '}
</InputGroup>
);
}
<ToDoListItem
key={data.Key}
Name={data.Name}
Checked={data.Checked}
onDelete={() => {
setDatas(datas.filter((a)=> a.Key !== data.Key))
}}
></ToDoListItem>
function ToDoListItem(props) {
return (
<InputGroup>
<InputGroup.Checkbox key={props.Key} checked={props.Checked} />
<Form.Control value={props.Name} />
<Button variant="danger" onClick={props.onDelete} >刪除</Button>{' '}
</InputGroup>
);
}
key={data.Key}
Name={data.Name}
Checked={data.Checked}
onDelete={() => {
setDatas(datas.filter((a)=> a.Key !== data.Key))
}}
const [datas, setDatas] = useState(GetData());
onClick={props.onDelete}
參考: